# $Id$
# Maintainer: Florian Pritz <bluewind@xinu.at>
# Contributor: Dale Blount <dale@archlinux.org>
# Contributor: Manolis Tzanidakis
pkgname=spamassassin
pkgver=3.4.1
pkgrel=10
pkgdesc="A mail filter to identify spam."
arch=('i686' 'x86_64')
license=('APACHE')
url="http://spamassassin.apache.org"
depends=('openssl' 'zlib' 're2c' 'perl-net-dns' 'perl-io-socket-ssl'
         'perl-libwww' 'perl-mail-spf' 'perl-http-message' 'perl-net-http'
         'perl-io-socket-inet6' 'perl-mail-dkim' 'perl-crypt-ssleay')
makedepends=('razor' 'perl-dbi')
optdepends=('razor: to identify collaborately-flagged spam'
            'make: to use sa-compile'
            'gcc: to use sa-compile')
backup=('etc/mail/spamassassin/local.cf'
        'etc/mail/spamassassin/init.pre'
        'etc/mail/spamassassin/v310.pre'
        'etc/mail/spamassassin/v312.pre'
        'etc/mail/spamassassin/v320.pre'
        'etc/mail/spamassassin/v330.pre')
install="${pkgname}.install"
source=("http://www.us.apache.org/dist/${pkgname}/source/Mail-SpamAssassin-${pkgver}.tar.gz"{,.asc}
        'spamassassin.service' net-dns-1.01-compat.patch net-dns-1.01-compat-uribl.patch disable-sslv3.patch 'bug_828552-openssl-1.1.0.patch' edb00a8d76a625bf03227ee2f6e915c9a0d90bad.patch)
validpgpkeys=(D8099BC79E17D7E49BC21E31FDE52F40F7D39814)
md5sums=('76eca1f38c11635d319e62c26d5b034b'
         'SKIP'
         '8adce028f25387ac3bc4dba697d209ed'
         '63458976671c35f423bd4e8033cfff3a'
         '14f2e3dc93c560d6b5a7fd7d54e44e11'
         'e6aeeae9828f305db72abb8707312ee7'
         '8de3e540060b5a0dce23d12420cb7902'
         'faec41f86be348c1d6f131612a8ee1fa')

prepare() {
  cd "${srcdir}/Mail-SpamAssassin-${pkgver}"

  sed -i t/sa_compile.t \
	  -e 's#^my $temp_binpath = $Config{sitebinexp};#my $temp_binpath = "/bin/site_perl/";#'

  patch -i "$srcdir/net-dns-1.01-compat.patch" -p3
  patch -i "$srcdir/net-dns-1.01-compat-uribl.patch" -p3

  # From Debian
  patch -i "$srcdir/disable-sslv3.patch" -p1
  patch -i "$srcdir/bug_828552-openssl-1.1.0.patch" -p1

  # FS#54378 - [spamassassin] sa-update Perl deprecation warnings
  patch -i "$srcdir/edb00a8d76a625bf03227ee2f6e915c9a0d90bad.patch" -p1
}

build() {
  cd "${srcdir}/Mail-SpamAssassin-${pkgver}"

  # install module in vendor directories.
  export PERL_USE_UNSAFE_INC=1
  PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor \
      CONTACT_ADDRESS=root@localhost ENABLE_SSL=yes PERL_TAINT=no
  make
}

check() {
  cd "${srcdir}/Mail-SpamAssassin-${pkgver}"

  # parallel tests cause lots of failures; disable for now
  #export HARNESS_OPTIONS="j$(echo $MAKEFLAGS | sed 's/.*-j\([0-9][0-9]*\).*/\1/')"

  make test
}

package() {
  cd "${srcdir}/Mail-SpamAssassin-${pkgver}"
  make DESTDIR="${pkgdir}" install

  install -D -m644 "${srcdir}/spamassassin.service" "${pkgdir}/usr/lib/systemd/system/spamassassin.service"
  install -d -o 182 -g 182 -m 755 "$pkgdir/var/lib/spamassassin"
}
